package cn.itlight.order.service.impl;

import cn.itlight.order.domain.OrderPetAcquisition;
import cn.itlight.order.domain.OrderProduct;
import cn.itlight.order.domain.OrderProductAcquisition;
import cn.itlight.order.dto.OrderConfirmDto;
import cn.itlight.order.mapper.OrderProductAcquisitionMapper;
import cn.itlight.order.mapper.OrderProductMapper;
import cn.itlight.order.service.IOrderProductAcquisitionService;
import cn.itlight.basic.service.impl.BaseServiceImpl;
import cn.itlight.pet.domain.Pet;
import cn.itlight.pet.domain.SearchMasterMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tomliu
 * @since 2022-07-21
 */
@Service
public class OrderProductAcquisitionServiceImpl extends BaseServiceImpl<OrderProductAcquisition> implements IOrderProductAcquisitionService {

    @Autowired
    private OrderProductAcquisitionMapper orderProductAcquisitionMapper;

    @Autowired
    private OrderProductMapper orderProductMapper;
    @Override
    public void confirm(OrderConfirmDto orderDto) {
        // 收购成功，根据订单Id查询订单，修改订单状态为已完成，修改价格
        OrderProductAcquisition orderProductAcquisition = orderProductAcquisitionMapper.loadById(orderDto.getId());
        orderProductAcquisition.setState(1);
        orderProductAcquisitionMapper.update(orderProductAcquisition);
        // 修改寻主状态为已完成
        OrderProduct orderProduct = orderProductMapper.loadById(orderProductAcquisition.getTOrderProductId());
        orderProduct.setState(1);
        orderProductMapper.update(orderProduct);

    }

    @Override
    public void cancelOrder(Long id) {
        // 将订单修改为拒绝
        OrderProductAcquisition orderProductAcquisition = orderProductAcquisitionMapper.loadById(id);
        orderProductAcquisition.setState(-1);
        orderProductAcquisitionMapper.update(orderProductAcquisition);
        // 2.将寻主消息的shopId置空，设置状态为已审核，归还到寻主池
        orderProductMapper.remove(orderProductAcquisition.getTOrderProductId());
    }
}
